package hit.dao;

import hit.dao.database.DatabaseDAOFactory;
import hit.dao.serialization.SerializationDAOFactory;

/**
 * References the DAOFactory to be used through the HIT's life-span. 
 *
 */
public class FactoryReference {

	/**
	 * The factory for the HIT.
	 */
	private static DAOFactory factory = null;
	
	/**
	 * Gets the current DAOFactory for saving the hit. If it hasn't been created yet,
	 * 	returns null.
	 * @return The DAOFactory
	 */
	public static DAOFactory GetFactory() {
		
		return factory;
	}
	
	/**
	 * Sets the DAOFactory to be a DatabaseFactory.
	 * @throws IllegalAccessException If the factory has already been created.
	 */
	public static void CreateDatabaseFactory() throws IllegalAccessException {
		
		if (factory != null)
			throw new IllegalAccessException();
		
		factory = new DatabaseDAOFactory();
	}
	
	/**
	 * Sets the DAOFactory to be a SerializationFactory.
	 * @throws IllegalAccessException If the factory has already been created.
	 */
	public static void CreateSerializationFactory() throws IllegalAccessException {
		
		if (factory != null)
			throw new IllegalAccessException();
		
		factory = new SerializationDAOFactory();
	}
}
